export default function parseTime(time, fm) {
  // 解析时间  time: 时间戳或者实践对象 fm: 格式 默认是{y}-{m}-{d} {h}:{i}:{s}
  if (arguments.length === 0) {
    return null
  }
  const format = fm || '{y}-{m}-{d} {h}:{i}:{s}'
  let date
  if (typeof time === 'object') {
    date = time
  } else {
    if (('' + time).length === 10) time = parseInt(time) * 1000
    date = new Date(time)
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  return format.replace(
    /{(y|m|d|h|i|s|a)+}/g,
    (result, key) => {
      let value = formatObj[key]
      if (key === 'a') {return ['一', '二', '三', '四', '五', '六', '日'][value - 1]}
      if (result.length > 0 && value < 10) {
        value = '0' + value
      }
      return value || 0
    }
  )
}
export function getTime(val){

  let date = new Date(val)

  let year = date.getFullYear()

  let month = date.getMonth()+ 1

  let day = date.getDate()

  let hour = date.getHours()

  let min = date.getMinutes()

  let seconds = date.getSeconds()

  if(month<10) month="0"+month;

  if(day<10) day="0"+day;

  if(hour<10) hour="0"+hour;

  if(min<10) min="0"+min;

  if(seconds<10) seconds="0"+seconds;

  return year + "-" + month + "-" + day

}
